package cn.ecut.servlet;

import cn.ecut.services.Commentservices;
import cn.ecut.services.Newsservices;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AddLikesServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //boolean isnews=req.getParameter("isnews");
        String id=req.getParameter("id");
        String msg="";
        if(true){
            Newsservices newsservices=new Newsservices();
            if(newsservices.AddLikes(id)){
                msg="点赞成功。";
                req.setAttribute("msg",msg);
                req.getRequestDispatcher("sucess.jsp").forward(req,resp);
            }else{
                msg="点赞失败。";
                req.setAttribute("msg",msg);
                req.getRequestDispatcher("false.jsp").forward(req,resp);
            }
        }
        else{
            Commentservices commentservices=new Commentservices();
            if(commentservices.AddLikes(id)){
                msg="点赞成功。";
                req.setAttribute("msg",msg);
                req.getRequestDispatcher("sucess.jsp").forward(req,resp);
            }else{
                msg="点赞失败。";
                req.setAttribute("msg",msg);
                req.getRequestDispatcher("false.jsp").forward(req,resp);
            }
        }
    }
}
